#include "CLFile.h"
#include <time.h>
#include <iostream>

using namespace std;

int main()
{
	CLFile f = CLFile();
	int flags = O_RDWR|O_APPEND;
	
	f.Open("file.txt", flags);
	
	cout << "----------------- Write --------------------" << endl;
	
	char str1[] = "ABCDE";
	cout << endl<< "Write string 1: " << str1 << endl;
	f.Write(str1, 5);
	
	char str2[] = "abcdefghij";
	cout << endl<< "Write string 2: " << str2 << endl;
	f.Write(str2, 10);
	
	char str3[] = "KLM";
	cout << endl<< "Write string 3: " << str3 << endl;
	f.Write(str3, 3);
	
	cout << endl << "Lseek 2 bytes after current position." << endl;
	f.Lseek(2, SEEK_CUR);
	
	char str4[] = "NOPQ";
	cout << endl<< "Write string 4: " << str4 << endl;
	f.Write(str4, 4);
	
	f.Close();
	
	f.Open("file.txt", flags);
	cout << "---------------Read---------------------" << endl;
	f.Lseek(0, SEEK_SET);

	char buf1[5];
	f.Read(buf1, 4);
	buf1[4] = '\0';
	cout << "String 1:" << buf1 << endl;

	char buf2[10];
	f.Read(buf2, 9);
	buf2[9] = '\0';
	cout << "String 2:" << buf2 << endl;

	cout << endl << "Lseek 2 bytes before current postion." << endl;
	f.Lseek(-2, SEEK_CUR);
	
	char buf3[3];
	f.Read(buf3, 2);
	buf3[2] = '\0';
	cout << "String3:" << buf3 << endl ;

	char buf4[5];
	f.Read(buf4, 4);
	buf4[4] = '\0';
	cout << "String4:" << buf4 << endl;
	
	f.Close();
	
	f.Open("file.txt", flags);
	cout << endl << "---------------ReadWrite---------------------" << endl;
	
	char str5[] = "1234567890";
	cout << endl << "Write string 5: " << str5 << endl;
	f.Write(str5, 10);
	
	char str6[] = "ABCDE";
	cout << endl << "Wrtie string 6: " << str6 << endl;
	f.Write(str6, 5);
	
	cout << endl << "Lseek 9 bytes before current position." << endl;
	f.Lseek(-9, SEEK_CUR);
	
	char buf5[4];
	f.Read(buf5, 3);
	buf5[3] = '\0';
	cout << "String 5: " << buf5 << endl;
	
	char str7[] = "xyz";
	cout << endl << "Write str7: " << str7 << endl;
	f.Write(str7, 3);

	cout << endl << "Lseek 4 bytes before current position." << endl;
	f.Lseek(4, SEEK_CUR);
	
	char buf6[6];
	f.Read(buf6, 5);
	buf6[5] = '\0';
	cout << "String 6: " << buf6 << endl;
	
	f.Close();
	return 0;
}
